package com.waterfairy.http.log;

import android.util.Log;

import com.waterfairy.http.utils.FormBodyUtils;
import com.waterfairy.http.utils.JsonBodyUtils;

import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;

/**
 * @user water_fairy
 * @mail 995637517@qq.com
 * @date 2021/8/5 5:14 下午
 * @info
 */
public class RequestLogUtils {
    public static synchronized void log(HttpUrl url, RequestBody body) {
        Log.i("request", "▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ ");
        String urlTemp = url.url().toString();
        if (body instanceof FormBody) {
            Log.i("request", " ► " + urlTemp + "?" + FormBodyUtils.getParams(body));
        } else if (body != null && body.contentType() != null && JsonBodyUtils.MEDIA_TYPE.equals(body.contentType().toString())) {
            //jsonBody
            Log.i("request", " ► " + urlTemp);
            Log.i("request", " ► " + JsonBodyUtils.getJsonParams(body));
        } else {
            Log.i("request", " ► " + urlTemp);
        }
        Log.i("request", "▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲");
    }
}
